using NUnit.Framework;
using Sandia.MVCFramework.Request;
using Sandia.MVCFramework.TestPlugin.Request;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sandia.MVCFramework.Test
{
    [TestFixture]
    public class RequestTests
    {
        [Test, ExpectedException(typeof(InvalidCastException))]
        public void StandardRequestParameterFactoryTest()
        {
            StandardRequestParameterFactory factory = 
                new StandardRequestParameterFactory();

            // This should throw an InvalidCastException...
            factory.CreateRequestParameter(typeof(string), null);

            // This should also throw an InvalidCastException...
            factory.CreateRequestParameter(typeof(ARequest), null);

            IRequestParameter parameter = factory.CreateRequestParameter(typeof(ERequestParameter), "data");

            Assert.IsTrue(parameter is ERequestParameter, "CreateRequestParameter returned the wrong type.");
            Assert.AreEqual("data", parameter.Data, "CreateRequestParameter did not set Data correctly.");
        }

        [Test]
        public void StandardRequestFactoryTest()
        {
            //

            StandardRequestFactory factory =
                new StandardRequestFactory();

            factory.CreateRequest(typeof(ERequest));

            System.Guid uniqueData = System.Guid.NewGuid();

            factory.SetParameter(typeof(ERequestParameter), uniqueData.ToString());

            string requesterID = Guid.NewGuid().ToString();
            ERequest request = (ERequest)factory.GetRequest(requesterID);

            Assert.AreEqual(uniqueData.ToString(), request[typeof(ERequestParameter).Name].Data.ToString(), "The data for the request parameter is not correct.");
            Assert.AreEqual(requesterID, request.RequesterID, "The requester ID's do not match.");
        }
    }
}
